package com.zhl.study.base;

import com.zhl.study.enums.IEnum;
import com.zhl.study.enums.SystemEnums;
import lombok.Data;

/**
 * @description 响应实体类
 * @Author: z156940l@outlook.com
 * @className Result
 * @Date: 2023/4/28 10:12
 */
@Data
public class Result<T> {
    /**
     * 状态码
     */
    private String code;
    /**
     * 响应信息
     */
    private String message;
    /**
     * 响应数据
     */
    private T data;

    public Result() {
        this.code = SystemEnums.SUCCESS.getCode();
        this.message = SystemEnums.SUCCESS.getMsg();
    }

    public Result(T data) {
        this.code = SystemEnums.SUCCESS.getCode();
        this.message = SystemEnums.SUCCESS.getMsg();
        this.data = data;
    }

    public Result(IEnum iEnum) {
        this.code = String.valueOf(iEnum.getCode());
        this.message = String.valueOf(iEnum.getMsg());
    }

    public Result(SystemEnums enums, T data) {
        this.code = enums.getCode();
        this.message = enums.getMsg();
        this.data = data;
    }

    public Result(String code, String msg) {
        this.code = code;
        this.message = msg;
    }

    public Result(String code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result(IEnum iEnum, String message, T data) {
        this.code = String.valueOf(iEnum.getCode());
        this.message = message;
        this.data = data;
    }
}